package com.season.seasonStudy.javase.j_017_enum0.petdemo;

import java.util.Scanner;

public class PetTest {
	static Scanner scanner = new Scanner(System.in);
	
	
	public static void main(String[] args) {
	
		/**
		 * 老师写了一个专门针对这个enum的显示方法
		 * 他的思想是字符串的拼接
		 */

		showByNumber();
		showByString();
	}
	
	/**
	 * 根据数字选择种类
	 * 输入字符串，进行选择
	 */
	public static void showByNumber() {
		System.out.println("请输入数字进行选择宠物种类：");
		System.out.println(PetType.dog.ordinal()+1
				+ PetType.dog.toString() +"  "+ PetType.qie.ordinal()+1
				+ PetType.qie.toString() +"  "+ PetType.cat.ordinal()+1
				+ PetType.cat.toString());
		
		int choice = scanner.nextInt();
		int index = choice-1;
		
		PetType petType = PetType.values()[index];
		
		System.out.println("--------------");
		System.out.println(petType.toString());
		System.out.println(petType.getPet().toString());
		System.out.println("--------------");
	}
	
	
	public static void showByString() {
		System.out.println("请输入字符串进行选择：");
		
		PetType[] pt = PetType.values();
		
		String str = "请选择宠物种类：（";
		
		StringBuffer sb = new StringBuffer(str);
		
		for (int i = 0; i < pt.length; i++) {
			sb.append(pt[i].ordinal()+1);
			sb.append(pt[i].toString());
			sb.append("、");
		}
		sb.append("）");
		str = sb.toString();
		System.out.println(str);
		
		String choice  = scanner.next();
		
		
		PetType p = PetType.valueOf(choice);
		p.getPet().play();
		System.out.println(p);
		System.out.println(p.toString());
	}
	
}
